﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public enum ChuanType
{
    KAOYANGROUCHUAN,
}

public class Desk : Item
{
    string[] needs = new string[1] { "rou(Clone)" };
    List<GameObject> chuans = new List<GameObject>();
    public Dictionary<ChuanType, int> dicNeed = new Dictionary<ChuanType, int>();
    GameObject uiCountdown;

    private void Awake()
    {
    }

    // Start is called before the first frame update
    public void Start()
    {
        base.Start();
        Object obj = Resources.Load("CustomerSitTime");
        uiCountdown = Instantiate(obj) as GameObject;
        uiCountdown.transform.SetParent(GameObject.Find("Canvas").transform, false);
        Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, transform.position);
        uiCountdown.GetComponent<RectTransform>().position = screenPoint + new Vector2(0, 320);
        uiCountdown.SetActive(false);
    }

    //public bool EnqueueChuan(GameObject go)
    //{
    //    if (chuans.Count < 5)
    //    {
    //        //chuans.Enqueue(go);
    //        for (int i = 0; i < chuans.Count; i++)
    //        {
    //            chuans.ElementAt(i).SetActive(true);
    //        }
    //        return true;
    //    }
    //    else return false;
    //}

    public override void TaskEnqueue(GameObject[] gameObjects)
    {
        for(int i = 0; i < needs.Length; i++)
        {
            for(int j = 0; j < gameObjects.Length; j++)
            {
                if (gameObjects[j].transform.GetChild(0).name == needs[i])
                {
                    gameObjects[j].transform.SetParent(transform);
                    gameObjects[j].transform.localPosition = new Vector3(0, 0.66f, 0);
                    gameObjects[j].transform.localRotation = Quaternion.Euler(0, 0, 0);
                }
            }
        }
        base.TaskEnqueue(gameObjects);
    }

    public override GameObject[] TaskDequeue(int n)
    {
        GameObject[] rg = new GameObject[n];
        for (int i = 0; i < n; i++)
        {
            //rg[i] = chuans.Dequeue();
        }
        for (int i = 0; i < chuans.Count; i++)
        {
            chuans.ElementAt(i).SetActive(true);
        }
        return rg;
    }

    public void StartLoop()
    {
        uiCountdown.SetActive(true);
        StartCoroutine(IELoop());
    }

    IEnumerator IELoop()
    {
        while (true)
        {
            yield return new WaitForSeconds(3);

        }
    }
}
